<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMenuTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('menus', function (Blueprint $table) {
            $table->integerIncrements('id');
            $table->integer('pid')->default(0)->nullable(false)->comment('父id');
            $table->unsignedInteger('menu_group_id')->nullable(false)->comment('导航组id')->after('pid');
            $table->unsignedTinyInteger('type')->default(2)->nullable(false)->comment('类型1-横向菜单2-父级菜单3-子级菜单');
            $table->unsignedTinyInteger('is_auth')->default(0)->nullable(false)->comment('是否开启权限验证1-是0-否');
            $table->string('label',20)->nullable(false)->comment('菜单名称');
            $table->string('route',100)->nullable(false)->comment('路由');
            $table->string('icon',100)->nullable(true)->comment('图标可选');
            $table->unsignedTinyInteger('status')->default(1)->nullable(false)->comment('状态1-启用0-禁用');
            $table->integer('sort')->default(99)->nullable(false)->comment('排序');
            $table->timestamps();
            $table->unique(['label','menu_group_id']);
            $table->foreign('menu_group_id')->references('id')->on('menu_groups')->onUpdate('cascade')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('menus');
    }
}
